
* Set directories

cd /Users/xiaosongw/Dropbox/Research/InformedSources/ReplicationRemove2

*-------------------- Figure 2: Retailer-Level Price Cycles -------------------*

* Load data
use ./Data/is_mel_p_2005_2019, clear

* Sample Period
keep if t>=td(1jan2014) & t<=td(31dec2018)
keep if bid==1 | bid==2 | bid==3 | bid==4 | bid==5

* Sample dimensions
sum p, detail
sort id t
by id: gen unq=1 if _n==1 
tab unq


* Dates for xlabels
local x1=td(1jan2014)
local x2=td(1jan2015)
local x3=td(1jan2016)
local x4=td(1jan2017)
local x5=td(1jan2018)
local x6=td(1jan2019)

* Compute mean price by market, brand, datex
sort bid t
collapse (mean) p c, by(bid t)


* Highlighting window where Coles starts losing access
gen yoff1=90
gen yoff2=170
gen y1=145
gen y2=145
gen x1=td(1jun2016)+3
gen x2=td(1may2016)+3
local xtext1=td(1jan2017)
twoway 	(rarea yoff1 yoff2 t if bid==1 & t>=td(1apr2016) & t<td(1may2016), vertical color(grey*0.20%30)) ///
		(line p t if bid==1, lwidth(vthin)   connect(stairstep) lcolor(green)  lpattern(dash)) ///
		(line p t if bid==2, lwidth(vthin)   connect(stairstep) lcolor(blue)   lpattern(shortdash) ) ///
		(line p t if bid==3, lwidth(vthin) connect(stairstep) lcolor(red)  lpattern(solid) ) ///
		(line p t if bid==4, lwidth(vthin)   connect(stairstep) lcolor(purple) lpattern(dash_dot)) ///
		(line p t if bid==5, lwidth(vthin)   connect(stairstep) lcolor(orange) lpattern(longdash)) ///
		(line c t if bid==1, lwidth(medium) connect(stairstep) lcolor(gs4) lpattern(shortdash)  ///		
		ytitle("Mean Station-Level Retail Price (cpl)", height(6)) ylabel(90(10)170, labsize(*0.8) grid) ///
		xtitle(" ", height(6)) ///
		xlabel(`x1' `" "Jan 1"  "2014" "' `x2' `" "Jan 1"  "2015" "' `x3' `" "Jan 1"  "2016" "' ///
			   `x4' `" "Jan 1"  "2017" "' `x5' `" "Jul 1"  "2018" "' `x6' `" "Jan 1"  "2019" "', labsize(*0.7)) ///
		plotregion(margin(zero) style(none)) ///
		legend(order(2 3 4 5 6 7) size(*0.75) position(11) symx(*0.5) symy(*0.5) region(lwidth(*0.05)) rows(1) ///
		label(2 "BP") label(3 "Caltex") label(4 "Coles") label(5 "Woolworths") label(6 "7-Eleven") label(7 "Wholesale" "TGP")) ///
		text(165 `xtext1' "Coles Informed Sources" "contract expires", justification(left) size(*0.7)))
graph export Output/fig2_prices.pdf, as(pdf) replace


